<?php
include_once "xAP-functions/webincludes.php";

	$title="Latest CCTV";

$script="
<script type=\"text/javascript\" >
var pics".$widgetID."=new Array();
var images".$widgetID."=new Array();
var currentpic".$widgetID."=0;
var picinterval".$widgetID."=0;
$(document).ready(function(){
	CCTVUpdate".$widgetID."();
	setInterval('CCTVUpdate".$widgetID."()',20000);
	clearInterval ( picinterval".$widgetID." );
});
function CCTVUpdate".$widgetID."(){	
	$.get(\"/".$config["modulefolder"]."/widget_CCTV_data.php?id=".intval($extradata["sourceid"])."\",function(data){
		var str=data;
		imageObj = new Array();
		pics".$widgetID."=str.split('~');
		currentpic".$widgetID."=0;
		for (i=0;i<pics".$widgetID.".length;i++){
			cpics=pics".$widgetID."[i].split('=');
			imageObj[i] = new Image();
			imageObj[i].src=\"/".$config["modulefolder"]."/image.php?id=\" + cpics[0] + \"&type=1\";
		}
		clearInterval ( picinterval".$widgetID." );
		picinterval".$widgetID."=setInterval('CyclePics".$widgetID."()',500);
	});
}
function CyclePics".$widgetID."(){
	if(currentpic".$widgetID.">= (pics".$widgetID.".length -1)){
		currentpic".$widgetID."=0;
	}
	cpics=pics".$widgetID."[currentpic".$widgetID."].split('=');
	$('#CCTVUpdate".$widgetID."').html(\"<center><img src='/".$config["modulefolder"]."/image.php?id=\" + cpics[0] + \"&type=1\' width=160 height=120><BR>\" + cpics[1] + \"</center>\");
	currentpic".$widgetID."++;	
}
</script>";

$body="<div class='boldtext' id='CCTVUpdate".$widgetID."'></div>";
echo LayoutWidget("widget_CCTV",$title,$body,$widgetID,$script);
?>